﻿using System;
using System.Data;

namespace DreamCube.Framework.Utilities.Report
{
    /// <summary>
    /// 列表元素的每一个列元素
    /// </summary>
    public class TableTD : Element
    {
        #region "字段"

        /// <summary>
        /// {0}:td的属性
        /// {1}:单元格的内容
        /// </summary>
        private String td = "<td {0}>{1}</td>";

        #endregion

        #region "属性"

        /// <summary>
        /// 对应TD的ColSpan属性
        /// </summary>
        public Int32 ColSpan
        {
            get;
            set;
        }

        /// <summary>
        /// 对应TD的RowSpan属性
        /// </summary>
        public Int32 RowSpan
        {
            get;
            set;
        }

        /// <summary>
        /// 字段名称
        /// </summary>
        public String FieldName
        {
            get;
            set;
        }

        /// <summary>
        /// 字段的CSS样式
        /// </summary>
        public String FieldCSS
        {
            get;
            set;
        }

        /// <summary>
        /// 字段的风格类名
        /// </summary>
        public String FieldStyle
        {
            get;
            set;
        }

        /// <summary>
        /// 控件类型
        /// </summary>
        public Enums.TableTDControlType TDControlType
        {
            get;
            set;
        }

        #endregion

        #region "方法"

        /// <summary>
        /// 把元素转换成HTML
        /// </summary>
        public String ToHtml(Object value)
        {
            String valueHtml = String.Empty;
            if (this.TDControlType == Enums.TableTDControlType.Input)
                valueHtml = String.Format("<input type='text' value='{0}' />", value);
            else if (this.TDControlType == Enums.TableTDControlType.Span)
                valueHtml = String.Format("<span>{0}</span>", value);

            String properties = String.Empty;
            if (this.ColSpan > 0) properties += String.Format(" colspan='{0}' ", this.ColSpan);
            if (this.RowSpan > 0) properties += String.Format(" rowspan='{0}' ", this.RowSpan);
            if (!String.IsNullOrEmpty(this.FieldStyle)) properties += String.Format(" class='{0}' ", this.FieldStyle);
            if (!String.IsNullOrEmpty(this.FieldCSS)) properties += String.Format(" style='{0}' ", this.FieldCSS);
            return String.Format(this.td, properties, valueHtml);
        }

        #endregion
    }
}
